package com.tanhua.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.tanhua.dubbo.mappers.UserMapper;
import com.tanhua.model.domain.User;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

@DubboService
public class UserApiImpl implements UserApi {

    @Autowired
    private UserMapper userMapper;
    @Override//根据电话查用户
    public User findByMobile(String mobile) {
        LambdaQueryWrapper<User> lqw =new LambdaQueryWrapper<>();
        lqw.eq(User::getMobile,mobile);
         return userMapper.selectOne(lqw);
    }

    @Override
    public Long save(User user) {
        userMapper.insert(user);
        return user.getId();
    }

    @Override
    public void update(User user) {
        userMapper.updateById(user);
    }

    @Override
    public User findById(Long aLong) {
        return userMapper.selectById(aLong);
    }

    @Override
    //根据环信账号查用户
    public User findByHuanxin(String huanxinId) {
        LambdaQueryWrapper<User> lqw =new LambdaQueryWrapper<>();
        lqw.eq(User::getHxUser,huanxinId);
        User user = userMapper.selectOne(lqw);
        return user;
    }
}
